var loadings = false
export const useForms = () => {

	const submit = (api, data, msg = "操作成功") => {
		console.log(loadings);
		return new Promise((resolve, reject) => {
			if (loadings) {
				return false
			}
			loadings = true
			uni.showLoading({})
			api(data).then(res => {
				uni.hideLoading()
				uni.showToast({
					icon: "success",
					title: msg,
					duration: 1000
				});
				resolve(res)
				setTimeout(() => {
					loadings = false
				}, 500)
			}).catch(err => {
				loadings = false
				uni.hideLoading()
				reject(err)
			})
		})
	}
	return {
		submit
	}
}